import {Injectable} from '@angular/core';
import {HttpProvider} from '../../common/http'
import {API} from "../../common/api";

@Injectable()
export class AuthProvider {
  static token: string

  constructor(public http: HttpProvider) {
    console.log('Hello AuthProvider Provider');
  }

  getFaceToken() {
    return this.http.ajax(API.GET_FACE_TOKEN).then(token => {
      AuthProvider.token = token
    })
  }

  upload(file) {
    let formData = new FormData()
    formData.append('image', file, "image.jpeg")
    formData.append('token', AuthProvider.token)
    console.log(formData)
    return this.http.request({
      type: 'POST',
      url: API.UPLOAD_IDCARD_FRONT,
      params: formData,
      headers: {
        //默认会使用 multipart/form-data 且自动设置 boundary
        'Content-Type': false
      }
    })
  }

}
